home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK2.toast / Development Kits (Disc 2) / QuickTime / Programming Stuff / Documentation / develop articles / develop Issue 12 / Time Bases / TimeBaseSlave / TimeBaseSlaveAux.p < prev   
Encoding:
Text File  |  1997-02-26  |  7.8 KB  |  322 lines  |  [TEXT/MPS ]

  1. (*********** Auxiliary routines ********************************************************)
  2.  
  3. PROCEDURE DoUpdate(theEvent : EventRecord);
  4. FORWARD;
  5.  
  6. PROCEDURE ErrorControl(message: Str255);
  7.  
  8. BEGIN
  9.     DebugStr(message);
  10. END;
  11.  
  12. (* The sample wants to show how callbacks are triggered over a period of time with
  13.    each invokation comming every three seconds, thererfor we need
  14.    the movie to have a reasonable duration. In this routine we extend the duration of
  15.    the movie if the duration is less than kMinDuration seconds.
  16. *)
  17.  
  18. PROCEDURE ExtendMovie(whichMovie: Movie);
  19. VAR moovDuration, desiredDuration: TimeValue;
  20.     times, count: Integer;
  21.     temp: Movie;
  22.     moovScale: TimeScale;
  23.     
  24. BEGIN
  25.   moovDuration := GetMovieDuration(whichMovie);
  26.   
  27.   (* need to convert our desired duration in seconds to movie time
  28.      so that we can compare what we want with the original duration *)
  29.   moovScale := GetMovieTimeScale(whichMovie);
  30.   desiredDuration := moovScale * kMinDuration; (* convert to movie time *)
  31.   
  32.   IF moovDuration < desiredDuration THEN (* compare durations *)
  33.     BEGIN
  34.       times := desiredDuration DIV moovDuration;
  35.       SetMovieSelection(whichMovie, 0, moovDuration); (* select whole movie *)
  36.       temp := CopyMovieSelection(whichMovie); (* and cut it *)
  37.       SetMovieSelection(whichMovie, moovDuration, moovDuration); (* select the end *)
  38.       FOR count := 1 to times DO
  39.         BEGIN
  40.           PasteMovieSelection(whichMovie, temp); (* add movie to itself *)
  41.             moovDuration := GetMovieDuration(whichMovie); (* get the new duration *)
  42.             SetMovieSelection(whichMovie, moovDuration, moovDuration); (* select the end *)
  43.         END;
  44.       DisposeMovie(temp);
  45.     END
  46. END;
  47.  
  48.  
  49. (* Sets the movie clip region in order to display only a piece of it *)
  50. PROCEDURE SplitMovie(moov: Movie; count: Integer);
  51. VAR cBox:    Rect;
  52.     rectRgn: RgnHandle;
  53.  
  54. BEGIN
  55.     rectRgn := NewRgn;
  56.     GetMovieBox(moov, cBox);
  57.     
  58.     WITH cBox DO
  59.         CASE count OF
  60.             1:BEGIN
  61.                  right := right DIV 2;
  62.                 bottom := bottom DIV 2;
  63.               END;
  64.             2:BEGIN
  65.                  left := right DIV 2;
  66.                 bottom := bottom DIV 2;
  67.               END;
  68.             3:BEGIN
  69.                 left := right DIV 2;
  70.                 top := bottom DIV 2;
  71.               END;
  72.             4:BEGIN
  73.                  right := right DIV 2;
  74.                 top := bottom DIV 2;
  75.               END
  76.         END; (* CASE *)
  77.     
  78.     OpenRgn;
  79.       FrameRect(cBox);
  80.     CloseRgn(rectRgn);
  81.     
  82.     SetMovieClipRgn(moov, rectRgn);
  83.     
  84.     DisposeRgn(rectRgn);
  85. END;
  86.  
  87.  
  88. PROCEDURE HandleGoAway(WPtr : WindowPtr; MLoc : Point);
  89. {
  90.     purpose         handle mouse click in go-away box
  91. }
  92. VAR
  93.   WPeek             : WindowPeek;           { for looking at windows    }
  94. BEGIN
  95.   IF WPtr = FrontWindow THEN                  { if it's the active window }
  96.     BEGIN
  97.       WPeek := WindowPeek(WPtr);            { peek at the window        }
  98.       IF TrackGoAway(WPtr,MLoc) THEN        {   and the box is clicked  } 
  99.         IF WPeek^.WindowKind = userKind THEN{     if it's our window    }   
  100.           gDoneFlag := True                   {       then time to stop   }
  101.     END   
  102.   ELSE 
  103.     SelectWindow(WPtr)                       { else make it active       }
  104. END; { of proc HandleGoAway }
  105.  
  106. PROCEDURE ShiftMoviePieces(count: Integer);
  107. VAR cBox:    Rect;
  108.     pos:    Integer;
  109.     hOff, vOff: Integer;
  110.     
  111. BEGIN
  112.  
  113.     GetMovieBox(gMoov[count], cBox);
  114.     
  115.     WITH cBox DO
  116.       BEGIN
  117.         hOff := (right - left);
  118.         vOff := (bottom - top);
  119.       END;
  120.       
  121.     pos := count + stage;
  122.     IF pos > 4 THEN
  123.       pos := pos - 4;
  124.     CASE pos OF
  125.         1:BEGIN
  126.             hOff := 0;
  127.             vOff := -vOff;
  128.           END;
  129.         2:BEGIN
  130.             vOff := 0;
  131.           END;
  132.         3:BEGIN
  133.             hOff := 0;
  134.           END;
  135.         4:BEGIN
  136.             vOff := 0;
  137.             hOff := -hOff;
  138.           END
  139.     END; (* CASE *)
  140.  
  141.     OffSetRect(cBox, hOff, vOff);
  142.     SetMovieBox(gMoov[count], cBox);
  143. END;
  144.  
  145. PROCEDURE HandleClicks;
  146. VAR    j:     Integer;
  147.  
  148. BEGIN
  149.     stage := (stage +1) MOD 4;
  150.  
  151.     FOR j:= 1 TO MoviePieces DO
  152.       BEGIN
  153.         ShiftMoviePieces(j);
  154.       END;
  155.      
  156. END;
  157.  
  158. PROCEDURE DoMouseDown(theEvent:EventRecord);
  159.     purpose         identify where mouse was clicked and handle it
  160. }
  161. VAR
  162.   Location      : Integer;
  163.   theWindow     :    WindowPtr;
  164.   MLoc          :    Point;
  165.   WLoc          :    Integer;
  166.   
  167. PROCEDURE DoButtonDown;
  168. {
  169. }
  170. VAR
  171.         t1, t2: Integer;
  172.         result: ComponentResult;
  173.         setInvisible: Boolean;
  174.         err: OSErr;
  175.         controllerBox: Rect;
  176. BEGIN
  177.     t1 := TickCount;
  178.     REPEAT
  179.       t2 := TickCount;
  180.     UNTIL NOT WaitMouseUp;
  181.     
  182.     IF t2 - t1 > 5 THEN
  183.       BEGIN
  184.         HandleClicks
  185.       END
  186. END;{ of proc DoButtonDown }
  187.  
  188. BEGIN
  189.   MLoc  := theEvent.Where;              { get mouse position            }
  190.   WLoc := FindWindow(MLoc,theWindow);   { get window, loc in window     }
  191.   CASE WLoc OF                          { handle window locations       }
  192.     InGoAway    : HandleGoAway(theWindow,MLoc);     { in the go away box}
  193.     OTHERWISE      DoButtonDown;
  194.   END;
  195. END; { of proc DoMouseDown }
  196.  
  197. PROCEDURE HandleEvent(theEvent : EventRecord);
  198.     purpose         decodes events and dispatched to handlers
  199. }
  200. BEGIN
  201.   CASE theEvent.What OF
  202.     mouseDown:         DoMouseDown(theEvent);      { mouse button pushed   }
  203.     updateEvt:        DoUpdate(theEvent);
  204.   END
  205. END; { of proc HandleEvent }
  206.  
  207. PROCEDURE InitVars;
  208. BEGIN
  209. { Initialization of variables used for time base samples }
  210.   doneSizing := FALSE;    { We want to resize the window just once     }
  211.   stage := 0;            { Where in the rotation we are                }
  212.   enslaving := TRUE;    { Using the time base slaving trick            }
  213.   gDoneFlag := FALSE;        { to begin with                        }
  214.   gForwardFlag := TRUE;        { start the movie playing forward    }
  215. END;
  216.  
  217. FUNCTION InitSystem: OSErr;
  218.     purpose         initialize everything for the program
  219.                     returns an error if QuickTIme is not present or
  220.                     if EnterMovies failed.
  221. }
  222. VAR
  223.   result: OSErr;
  224.  
  225. FUNCTION GetGestaltResult(gestaltSelector: OSType):Integer;
  226. VAR
  227.   result : LONGINT;
  228. BEGIN
  229.   IF Gestalt(gestaltSelector, result) = noErr THEN
  230.     GetGestaltResult := result
  231.   ELSE
  232.     GetGestaltResult := 0;
  233. END;
  234.  
  235. BEGIN
  236.  
  237.   MaxApplZone;
  238.   
  239.   { initialize all the different managers                               }
  240.   InitGraf(@thePort);               { create a grafport for the screen  }
  241.   InitFonts;                        { start up the font manager         }
  242.   InitWindows;                      { start up the window manager       }
  243.   InitMenus;                        { start up the menu manager         }
  244.   TEInit;                           { start up the text manager for DAs }
  245.   InitDialogs(NIL);                 { start up the dialog manager       }
  246.   FlushEvents(everyEvent,0);        { clear events from previous state  }
  247.   
  248.   WITH wRect DO        { Use this routine to init the window rect }
  249.     BEGIN
  250.       top:= 40;
  251.       left:= 20;
  252.       bottom := 240;
  253.       right := 220;
  254.     END;
  255.   
  256.   gSystemVersion := GetGestaltResult (gestaltSystemVersion);
  257.   
  258.   IF GetGestaltResult(gestaltQuickTime) <> 0 THEN { zero means no such selector }
  259.     result:= EnterMovies
  260.   ELSE
  261.     result := movieToolboxUnitialized;
  262.     
  263. { Initialization of variables used for time base samples }
  264.   InitVars;
  265.   
  266.   InitSystem := result;
  267. END; (* InitSystem *)
  268.  
  269. PROCEDURE ConvertOldToNew(oldSF: SFReply; VAR newSF: StandardFileReply);
  270.     purpose         converts an old style SFReply inot a system 7
  271.                     StandardFileReply.
  272. }
  273. VAR        err:            OSErr;
  274.         ignoreProc:        LONGINT;
  275.         
  276. BEGIN
  277.       WITH newSF, oldSF DO
  278.       BEGIN
  279.         sfGood := good;
  280.         sfReplacing := copy;
  281.         sfType := fType;
  282.         err := FSMakeFSSpec(vRefNum, 0, fName, sfFile);
  283.         sfScript := iuSystemScript;
  284.         sfFlags := 0;
  285.         sfIsFolder := false;
  286.         sfIsVolume := false;
  287.         sfReserved1 := 0;
  288.         sfReserved2 := 0;
  289.       END;
  290. END;
  291.  
  292. FUNCTION DisplayGetFile(prompt: Str255; VAR reply: StandardFileReply): BOOLEAN;
  293.     purpose         promp the user to select a file works in both system 6 and 7.
  294. }
  295. VAR        fileTypes:        SFTypeList;
  296.         localReply:        SFReply;
  297.         where:            Point;
  298.         err:            OSerr;
  299. BEGIN
  300.     where.h:=100;
  301.     where.v:=100;
  302.     fileTypes[0]:='MooV';
  303.     
  304.     IF gSystemVersion >= $0700 THEN     { new standard file available }
  305.       StandardGetFilePreview(nil, 1, fileTypes, reply)    
  306.     ELSE
  307.       BEGIN
  308.         SFGetFIle(where, prompt, nil, 1, fileTypes, nil, localReply);
  309.         ConvertOldToNew(localReply, reply);
  310.       END;
  311.     DisplayGetFile := reply.sfGood;
  312. END;
  313.  
  314.  
  315. (******* END Auxiliary routines ********************************************************)
  316.  
  317.